package com.dream.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Component;

import com.dream.common.Common;
import com.dream.common.SuperDao; 
import com.dream.model.Sys_Dict;
import com.dream.system.service.IDict;

@Component("dictServiceImpl")
public class DictServiceImpl extends SuperDao<Object> implements IDict
{

	@Override
	public int addDict(Sys_Dict model)
	{
		// TODO Auto-generated method stub
		model.setCreateTime(Common.getTime1());
		model.setShowTime(Common.getTime());
		this.addT(model);
		return 1;
	}

	@SuppressWarnings("all")
	@Override
	public Map getDict(Sys_Dict model)
	{
		// TODO Auto-generated method stub
		String hql = " from Sys_Dict t ";
		@SuppressWarnings("unchecked")
		List<Sys_Dict> list1 = (List<Sys_Dict>) this.getList(hql, model.getStart(), model.getLimit(), "");
		int count = this.getListCount("select count(*) " + hql, "");
		Map map = new HashMap();
		map.put("count", count % model.getLimit() > 0 ? count / model.getLimit() + 1 : count / model.getLimit());
		map.put("list", list1);
		map.put("sum", count);
		return map;
	}

	@Override
	public int deletedict(String allId, String flag)
	{
		// TODO Auto-generated method stub
		if (null == allId || "".equals(allId))
		{
			return 0;
		} else
		{
			JSONArray jsonarr = JSONArray.fromObject(allId);
			for (int i = 0; i < jsonarr.size(); i++)
			{
				String table_id = jsonarr.getString(i);
				Sys_Dict su = (Sys_Dict) this.getT(new Sys_Dict(), table_id);
				this.delete(su);
			}
		}
		return 1;
	}

	@Override
	public List<String> getDisnetctDict(Sys_Dict dict)
	{
		// TODO Auto-generated method stub
		String hql = " select distinct t.dictSign from Sys_Dict t ";
		@SuppressWarnings("unchecked")
		List<String> list1 = (List<String>) this.getList(hql,0,0, "");
		return list1;
	}

}
